Skip to content

🧪 eliminate sys.path.insert hacks — migrate to package-relative imports#270

Closed
sheepdestroyer wants to merge 3 commits into
masterfrom
chore/eliminate-sys-path-hacks-565508234636993796
Closed

🧪 eliminate sys.path.insert hacks — migrate to package-relative imports#270
sheepdestroyer wants to merge 3 commits into
masterfrom
chore/eliminate-sys-path-hacks-565508234636993796

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jul 12, 2026

Copy link
Copy Markdown
Owner

🎯 What: This PR removes vestigial sys.path.insert hacks from 9 scripts in the scripts/ directory, migrating them to use standard package-relative imports. This cleanup follows the addition of init.py files in PR #264/#265 and ensures a cleaner, more robust import structure. It also adds a missing init.py to the router/ directory and updates router/main.py to use package-aware imports.

Fixes #266


PR created automatically by Jules for task 565508234636993796 started by @sheepdestroyer

Summary by CodeRabbit

  • Refactor
    • Improved package-based module loading for the router and supporting scripts.
    • Removed runtime path adjustments from benchmarking, classification, retry, and verification tools.
    • Standardized script imports for more predictable execution.
    • Preserved existing routing, classification, benchmarking, and verification behavior.

Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @sheepdestroyer, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@sheepdestroyer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b959892c-8bf2-403a-8548-624796e396b5

📥 Commits

Reviewing files that changed from the base of the PR and between a1820f5 and 4c32637.

📒 Files selected for processing (8)
  • router/main.py
  • scripts/benchmark_classifier.py
  • scripts/classify_direct.py
  • scripts/reclassify_all.py
  • scripts/retry_errors.py
  • scripts/verification/verification_helpers.py
  • scripts/verification/verify_canonical_endpoints.py
  • scripts/verification/verify_ollama_routing.py
📝 Walkthrough

Walkthrough

The change removes startup sys.path mutations from scripts, updates router import resolution for package execution, and sets benchmark environment variables explicitly.

Changes

Package import cleanup

Layer / File(s) Summary
Router package import setup
router/main.py, scripts/benchmark_tokens.py
router.main uses a relative circuit-breaker import, and token benchmarking no longer adjusts sys.path while setting its router environment variables.
Script package resolution
scripts/benchmark_classifier.py, scripts/classify_direct.py, scripts/reclassify_all.py, scripts/retry_errors.py, scripts/verification/*
Classifier and verification scripts remove runtime sys.path modifications and continue using package-based imports.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning benchmark_tokens.py adds import-time CONFIG_PATH and hardcoded ROUTER_API_KEY setup, which goes beyond the import-path cleanup requested. Move environment setup out of import time or keep this PR limited to removing sys.path.insert usage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the sys.path.insert cleanup and package-relative import migration.
Linked Issues check ✅ Passed The changes remove the targeted sys.path.insert hacks and update imports to package-aware forms as requested.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/eliminate-sys-path-hacks-565508234636993796

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request cleans up the codebase by removing dynamic sys.path modifications across several benchmark and verification scripts. It also updates the import of circuit_breaker in router/main.py. Feedback suggests using an explicit relative import instead of an absolute import in router/main.py to align with PEP 8 standards for package-relative imports.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread router/main.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/benchmark_classifier.py`:
- Around line 3-10: Update the chat_helpers import in benchmark_classifier.py so
it remains runnable when invoked directly as python
scripts/benchmark_classifier.py, using a sibling-import fallback that preserves
module execution compatibility, or explicitly switch to and document module
execution instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dab2f421-32e7-49f6-914e-5364c9c10697

📥 Commits

Reviewing files that changed from the base of the PR and between 3f7f503 and a1820f5.

📒 Files selected for processing (11)
  • router/__init__.py
  • router/main.py
  • scripts/benchmark_classifier.py
  • scripts/benchmark_tokens.py
  • scripts/classify_direct.py
  • scripts/reclassify_all.py
  • scripts/retry_errors.py
  • scripts/verification/verification_helpers.py
  • scripts/verification/verify_breaker.py
  • scripts/verification/verify_canonical_endpoints.py
  • scripts/verification/verify_ollama_routing.py
💤 Files with no reviewable changes (7)
  • scripts/verification/verify_canonical_endpoints.py
  • scripts/verification/verify_breaker.py
  • scripts/reclassify_all.py
  • scripts/verification/verify_ollama_routing.py
  • scripts/retry_errors.py
  • scripts/verification/verification_helpers.py
  • scripts/benchmark_tokens.py

Comment thread scripts/benchmark_classifier.py Outdated
- Revert 'from .circuit_breaker' to 'from router.circuit_breaker' in main.py:
  relative imports break when main.py is imported directly as 'main'
  (tests use 'from main import ...' with PYTHONPATH=.:router)
- Add try/except ImportError fallback to 'from scripts.chat_helpers'
  across all 7 scripts (4 in scripts/, 3 in verification/)
  so they remain runnable via both package import and direct execution
@sheepdestroyer

Copy link
Copy Markdown
Owner Author

Closing in favor of a fresh PR with all review fixes applied: reverted Gemini false-positive relative import (was breaking CI) and added ImportError fallbacks to all chat_helpers imports. See #271.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: eliminate sys.path.insert hacks — migrate to package-relative imports

1 participant